package com.yihu.wlyy.repository;

import com.yihu.wlyy.entity.DrHealthTeamMember;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * Created by Administrator on 2016/7/30.
 */
public interface DrHealthTeamMemberDao extends
        PagingAndSortingRepository<DrHealthTeamMember, Long>,
        JpaSpecificationExecutor<DrHealthTeamMember> {


    @Query(" FROM DrHealthTeamMember a WHERE a.team=?1 and a.type=?2 and a.del='1'")
    DrHealthTeamMember findDoctor2ByTeam(String code, int type);


    @Query(" FROM DrHealthTeamMember a WHERE a.team=?1 and a.type=?2 and a.del='1'and signType='1'")
    DrHealthTeamMember findDoctorSanshi2ByTeam(String code, int type);

    @Query(" FROM DrHealthTeamMember a WHERE a.team=?1 and a.type=?2 and a.del='1'and signType='2'")
    DrHealthTeamMember findDoctorJiating2ByTeam(String code, int type);

    @Query(" FROM DrHealthTeamMember a WHERE a.team=?1 and a.memberCode=?2 and a.del='1'")
    DrHealthTeamMember findMemberCodeAndTeam(String code, String doctor);

    @Modifying
    @Query("update DrHealthTeamMember a set a.del = '0' where a.team = ?1 and a.type=1 ")
    void updateType1Del(String code);

    @Modifying
    @Query("update DrHealthTeamMember a set a.del = '0' where a.team = ?1 and signType='2' ")
    void deleteMember(String code);

    @Query("select count(a) FROM DrHealthTeamMember a WHERE a.memberCode =?1 and  a.del='1'")
    Integer teamListByDoctorCode(String doctorCode);

    @Query(" FROM DrHealthTeamMember a WHERE a.team =?1 and  a.del='1' and  a.signType='1'")
    List<DrHealthTeamMember> findBySanshiTeam(String teamCode);

    @Query(" FROM DrHealthTeamMember a WHERE a.team =?1 and  a.del='1' and  a.signType='1' and  a.type=?2 ")
    DrHealthTeamMember findSanshiByTeamAndType(String teamCode, int i);

    List<DrHealthTeamMember> findByTeamAndDel(String team, String del);
}
